The sine of angle (degrees, 0 = east, counterclockwise) - a value from -1 to 1.
angle_sin(angle) -> real| Name | Type |
|---|---|
angle | real |
real
The sine of angle - degrees, 0 is east, counterclockwise, the same convention dir_to and every other angle in GBML already uses. Always somewhere between -1 and 1.
On its own this is just a number; paired with angle_cos it is how a circle gets drawn one point at a time - anything that moves in a loop, an arc, or a wave reaches for this pair.
direction += 3;
x = xstart + (angle_cos(direction) * 24);
y = ystart - (angle_sin(direction) * 24);Circles this object around wherever it spawned, 24 pixels out - direction doubles as the orbit's own current angle here, advancing a little more every frame. The minus in front of angle_sin is not a typo: the room's Y axis grows downward, but angle_sin grows the way a maths textbook does (upward), so the sign has to flip to turn "the sine of this angle" into "how far down the screen." dir_y already does exactly this flip - reach for dir_x/dir_y directly instead of writing it out by hand whenever a plain direction-and-length is all a piece of code actually needs.
The Game Boy Advance module's own fixed-point sine, not a coarse lookup table read - checked against true sine over 57,601 sample angles from four full turns before zero to four full turns after: the worst answer found anywhere in that sweep was off by 0.000434, under two of real's own smallest steps (1/4096). In practice that is not a separate source of error to plan around - it disappears into the fixed-point resolution the rest of the engine already lives with.
Works for any angle at all, not only 0 to 360 - a direction that keeps climbing past a full turn (exactly what the orbit above does) never needs wrapping back into range first.
the GBA module’s own fixed-point sine approximation (its degrees sine function), not a coarse lookup table read - checked against true sine over 57,601 sample angles, four full turns either side of zero: the largest error found was 0.000434, under two of real’s own smallest steps (1/4096) - in practice no worse than real itself already is. Works for any angle, not only 0-360 - a continuously accumulating angle never needs wrapping first. One 64-bit multiply-shift, the same cost dir_to already pays for its own angle work.